from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle('demo_389_简单动画')
        self.resize(500, 500)
        self.setup_ui()

    def setup_ui(self):
        self.simple_animation()

    def simple_animation(self):
        btn = QPushButton('test_move', self)

        animation = QPropertyAnimation(self)

    # 常用属性： pos size geometry windowOpacity


    # ***************位置改变*********************
        # 设置 要改变的属性量:
        animation.setTargetObject(btn)
        animation.setPropertyName(b'pos')
        # 设置 动画属性起始值
        animation.setStartValue(QPoint(0, 0))
        # 设置 动画属性终止值
        animation.setEndValue(QPoint(300, 300))
        # 设置 动画时长
        animation.setDuration(3000)
        #animation.setEasingCurve(QEasingCurve.InQuad)
        #animation.setEasingCurve(QEasingCurve.InBounce)
        animation.setEasingCurve(QEasingCurve.OutBounce)

        animation.currentLoopChanged.connect(lambda val: print('loop count changed', val))
        animation.finished.connect(lambda: print('animation finished!'))
        animation.stateChanged.connect(lambda newstate, oldstate:
                                       print('animation state changed from', oldstate, newstate))
        animation.setLoopCount(3)

        
        # 启动动画
        animation.start()
    # ************************************

    # ***************Size改变*********************
    #     animation.setTargetObject(btn)
    #     animation.setPropertyName(b'size')
    #     animation.setStartValue(QSize(0, 0))
    #     animation.setEndValue(QSize(300, 300))
    #     animation.setDuration(3000)
    #     animation.start()
    # ************************************

    # ***************geometry*********************
    #     animation.setTargetObject(btn)
    #     animation.setPropertyName(b'geometry')
    #     animation.setStartValue(QRect(0, 0, 100, 100))
    #     animation.setEndValue(QRect(300, 300, 200, 200))
    #     animation.setDuration(3000)
    #     animation.start()
    # ************************************

    # ***************windowOpacity*********************
    #     animation.setTargetObject(self)
    #     animation.setPropertyName(b'windowOpacity')
    #     animation.setStartValue(1)
    #     animation.setKeyValueAt(0.5, 0.5)
    #     animation.setEndValue(0.2)
    #     animation.setDuration(3000)
    #     animation.start()
    # ************************************


if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)

    win = Window()
    win.show()
    
    sys.exit(app.exec_())
